﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SlgEntityHero : BattleEntityHeroBase
{
    public NStateMachine<SlgEntityHero> m_pStateMachine;

    public override void OnCreate(params object[] args)
    {
        HeroVo vo = args[0] as HeroVo;
        GameObject model = args[1] as GameObject;
        Vector3 pos = (Vector3)args[2];
        base.OnCreate(vo, model);

        m_pGameObj.transform.position = pos;
        m_pGameObj.name = "Hero_" + vo.index;
        m_pRender.transform.localEulerAngles = new Vector3(30, 0, 0);
        m_pRender.transform.localScale = Vector3.one * SlgFightDef.FHeroSize;

        Dictionary<string, NState<SlgEntityHero>> states = new Dictionary<string, NState<SlgEntityHero>>()
        {
            {SlgHeroState.c_sSlgHero_Idle,SlgHeroState.c_pSlgHeroState_Idle},
            {SlgHeroState.c_sSlgHero_Move,SlgHeroState.c_pSlgHeroState_Move},
            {SlgHeroState.c_sSlgHero_Skill,SlgHeroState.c_pSlgHeroState_Skill },
            {SlgHeroState.c_sSlgHero_DoBuf,SlgHeroState.c_pSlgHeroState_DoBuf },
            {SlgHeroState.c_sSlgHero_Win,SlgHeroState.c_pSlgHeroState_Win }
        };
        m_pStateMachine = new NStateMachine<SlgEntityHero>(this, states, BattleHeroState.c_sMState_Global);
        ChangeState(SlgHeroState.c_sSlgHero_Idle);
    }

    public override bool HandleMessage(MessageBody body)
    {
        return m_pStateMachine.OnHandleMessage(body);
    }

    public override void OnUpdate(float deltaTime)
    {
        base.OnUpdate(deltaTime);
        m_pStateMachine.OnUpdate();
        m_pSkele.timeScale = SlgBattleMgr.Instance.Speed;
    }

    public override void ChangeState(string state, params object[] args)
    {
        m_pStateMachine.ChangeState(state, args);
    }

    public override void OnDestroy()
    {
        GameObject.Destroy(m_pGameObj);
    }
}

public class SlgHeroState
{
    public const string c_sSlgHero_Skill = "slg_hero_skill";
    public const string c_sSlgHero_Move = "slg_hero_move";
    public const string c_sSlgHero_Idle = "slg_hero_idle";
    public const string c_sSlgHero_DoBuf = "slg_hero_dobuf";
    public const string c_sSlgHero_Win = "slg_hero_win";

    public static SlgHeroStateIdle c_pSlgHeroState_Idle = new SlgHeroStateIdle();
    public static SlgHeroStateMove c_pSlgHeroState_Move = new SlgHeroStateMove();
    public static SlgHeroStateSkill c_pSlgHeroState_Skill = new SlgHeroStateSkill();
    public static SlgHeroStateDoBuf c_pSlgHeroState_DoBuf = new SlgHeroStateDoBuf();
    public static SlgHeroStateWin c_pSlgHeroState_Win = new SlgHeroStateWin();
}
